package com.wufeng.model.SpringBootModel.util;

import com.alibaba.fastjson.JSONObject;
import lombok.var;

import java.util.*;

public class MapUtil {
    public static void main(String[] args) {
        String str = "string";
        if (str.equals("str")) {

        }
        if (str != null) { // str.nn

        }
        if (str == null) { // str.null

        }
        ArrayList<String> list = new ArrayList<>(Arrays.asList("a,b,c,d".split(",")));
        for (int i = 0; i < list.size(); i++) { // list.fori

        }
        for (String s : list) { // list.for

        }

        Object obj = "test";
        String s = (String) obj;
        // new LinkedHashMap<>(8).var;
        LinkedHashMap<String, String> stringStringLinkedHashMap = new LinkedHashMap<>(8);
        var stringStringHashMap = new HashMap<String, String>(); // new HashMap<String, String>().varl
        HashSet<String> stringHashSet = new HashSet<>();
    }

    /**
     * JSONObject 底层实现是hashMap，默认无序的
     * 传入linkedHashMap对象，实现有序
     */
    public static void testLinkedHashMap() {
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("test1", "111");
        jsonObject1.put("test2", "222");
        jsonObject1.put("test3", "333");
        System.out.println("无序：");
        jsonObject1.keySet().stream().forEach(System.out::println);

        JSONObject jsonObject2 = new JSONObject(new LinkedHashMap<>());
        jsonObject2.put("test1", "111");
        jsonObject2.put("test2", "222");
        jsonObject2.put("test3", "333");
        System.out.println("有序：");
        jsonObject2.keySet().stream().forEach(System.out::println);
    }
}
